<?php
/**
 * 单页控制器
 */
namespace Admin\Controller;
use Think\Controller;
class UserController extends InitController {

	// 会员列表
	public function memberList() {
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];

		// 获取等级列表
		$level_list = getMemberLevelList(true);

		$show_level = $level_list;
		$show_level[5] = '非会员';
		ksort($show_level);

		$mobile = I('mobile');
		$member_name = I('member_name');
		$weixin = I('weixin');
		$member_level = intval(I('member_level'));
		$member_disable = intval(I('member_disable'));
		$start_time = strtotime(I('start_time'));
		$end_time = strtotime(I('end_time'));
		
		$where = array();

		if (!empty($mobile)) {
			$where['mobile'] = array('LIKE', '%'.$mobile.'%');
		}

		if (!empty($member_name)) {
			$where['username'] = array('LIKE', '%'.$member_name.'%');
		}

		if (!empty($weixin)) {
			$where['weixin'] = array('LIKE', '%'.$weixin.'%');
		}

		if ($show_level[$member_level]) {
			$where['level'] = $level_list[$member_level] ? $member_level : 0;
		}

		if (!empty($member_disable))
		{
			$where['disable'] = $member_disable == 1 ? 1 : 0;
		}

		if (!empty($start_time) && !empty($end_time)) {
			// 如果有开始及结束时间 则取中值
			$where['createtime'] = array(array('EGT', $start_time), array('ELT', $end_time));
		}else{
			if (!empty($start_time)) {
				// 有开始时间 
				$where['createtime'] = array('EGT', $start_time);
			}elseif (!empty($end_time)) {
				// 有结束时间 
				$where['createtime'] = array('ELT', $end_time);
			}
		}

		// dump($where);

		$member_list = M('user')->where($where)->page('1,10')->getField('id,mobile,createtime,level,username,weixin,disable,status');

		// dump($member_list);

		$this->assign(array(
			'level_list' => $level_list,	// 等级列表
			'show_level' => $show_level,	// 等级列表
			'member_list' => $member_list,
			'mobile' => $mobile,
			'member_name' => $member_name,
			'weixin' => $weixin,
			'member_level' => $member_level,
			'member_disable' => $member_disable,
			'start_time' => $start_time,
			'end_time' => $end_time,
		));
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('memberList');
	}

}